var port = 3600;
var hostname = 'localhost';


var http = require('http');

var url = require('url')

var route = require('./route')



var server = http.createServer((req,res)=>{

    // console.log(req.url);
    // var pathname = url.parse(req.url).pathname.replace(/\//,'');

    // if(pathname != '/favicon.ico'){

    //     res.writeHead(200,{'content-type':'text/html;charset=utf8'});
    //     res.write('<h2>首页</h2>')
    //     res.end();

    // }

    if(req.url != '/favicon.ico'){
        var pathname = url.parse(req.url).pathname.replace(/\//,'');
        // console.log(pathname);
        // route.home(req,res);

        try{
            route[pathname](res,req);
        }
        catch(err){
            route['notfound'](res,req)
        }



        // if(pathname == "home"){
        //     console.log(8888);
        //     route.home(res,req)
        //     // route['home'](req,res)
        // }
    
    }

}).listen(port,hostname,()=>{
    console.log('server is listen at'+port);
})